// pages/mys/hudong/share/play/index.js
const app = getApp(); // 获取应用实例
var Utils = require('../../../../../utils/crypt.js'); //加密解密

Page({

  /**
   * 页面的初始数据
   */
  data: {
    vw: 0, vh: 0, pvh: 0, 
    vid: 0, vlink: '', vcover: '', 
    lists: [], total: 0,
  },

  /**
   * 生命周期函数--监听页面加载
   */
  onLoad: function (options) {
    console.log(options);
    var that = this;
    var vid = options.vid;
    var cover = options.cover;
    var link = options.link;
    cover = Utils.decrypt(cover);
    link = Utils.decrypt(link);
    this.setData({
      vid: vid, vcover: cover, vlink: link,
    });
    that.getIndex();
  },
  //视频宽高自动获取
  videometa: function (e) {
    var that = this;
    //获取系统信息
    wx.getSystemInfo({
      success (res) {
        that.setData({
          vw: res.screenWidth,
          vh: res.screenHeight,
          pvh: res.windowHeight
        });
      }
    })
  },

  /**
   * 生命周期函数--监听页面初次渲染完成
   */
  onReady: function () {

  },

  /**
   * 生命周期函数--监听页面显示
   */
  onShow: function () {

  },

  /**
   * 生命周期函数--监听页面隐藏
   */
  onHide: function () {

  },

  /**
   * 生命周期函数--监听页面卸载
   */
  onUnload: function () {

  },

  /**
   * 页面相关事件处理函数--监听用户下拉动作
   */
  onPullDownRefresh: function () {

  },

  /**
   * 页面上拉触底事件的处理函数
   */
  onReachBottom: function () {

  },

  /**
   * 用户点击右上角分享
   */
  onShareAppMessage: function () {

  },

  //返回
  toBack: function () {
    console.log('返回');
    wx.showToast({
      title: '即将返回。。', icon: 'none'
    })
    wx.redirectTo({
      url: '/pages/mys/hudong/share/index'
    })
  },
  //获取评论列表
  getIndex: function () {
    var that = this;
    // console.log(that.data)
    //请求数据
    wx.request({
      url: app.globalData.domain+'/my/video/fx/one',
      method: "POST",
      header: {'content-type': 'application/x-www-form-urlencoded'},
      data: {
        wx:app.globalData.usertest, 
        vid:that.data.vid, 
      },
      success: function (res) {
        wx.hideLoading();
        if (res.data.code!=0) {
          wx.showToast({
            title: '没有评论，来发一条。。', icon: 'none'
          }); return
        } 
        var lists = res.data.data;
        var total = res.data.total;
        console.log(lists)
        //设置数据
        that.setData({
          lists: lists, total: total,
        });
      }
    });
  },
  //去更多
  toMore: function () {
    console.log('更多。。');
    wx.showToast({
      title: '即将去更多。。', icon: 'none',
    })
  },
})